import { observable, action } from 'mobx';
import { WeaTableNew, WeaForm } from 'comsMobx';

const { TableStore } = WeaTableNew;


/**
 * 列表页面，基础store
 */
export default class ListBaseStore {
	@observable tableStore = new TableStore();
	/** 列表store */
	@observable title = '';
	@observable loading = false; // 加载中状态
	@observable sessionkey = ''; // 表格sessionkey

	/** 高级查询store */
	@observable carInfo = {} ;
	@observable form = new WeaForm(); // 表单
	@observable showSearchAd = false; // 高级搜索面板是否展示
	@observable conditioninfo = []; // 高级搜索条件

	/** 顶部Tab组件store */
	@observable selectedKey = ''; // 顶部tab选中值
	@observable topTab = []; // 顶部tab
	@observable topTabCounts = {}; // 顶部tab count值

	 /** 左侧树store */
	 @observable selectedTreeKeys = [];
	 @observable leftTreeDatas = [];
	 @observable leftTreeTypes = [];
	 @observable leftTreeCounts = {};


	// 设置标题
	@action setTitle = (title) => {
	  this.title = title;
	}

	// 获取form当前的值
    @action getFormParams = () => this.form.getFormParams()

    // 清空高级搜索表单里面所有字段的值
    @action resetAdSearchForm = () => {
      this.form.reset();
    }

	// 展示或隐藏 加载中状态条
	@action showLoading = (bool) => {
	  this.loading = bool;
	}

	// 展示或隐藏 高级搜索条件面板
	@action setShowSearchAd = (bool) => {
	  this.showSearchAd = bool;
	}

	// 顶部tab标志
	@action setSelectedKey = (selectedKey = '') => {
	  this.selectedKey = selectedKey;
	}


	@action initFormFields = (conditioninfo) => {
	  this.form.initFormFields(conditioninfo);
	}

	@action setFormFields = (value) => {
	  this.form.updateFields(value, true); // true代表完全覆盖方式更新条件值
	}

    @action appendFormFields = (value) => {
      this.form.updateFields(value, false);
    }

    @action clearFormFields = () => {
      this.form.reset(); // 清除查询条件值
    }

	// 重新初始化一个form
	@action reinitializeForm = (conditioninfo) => {
	  this.form = new WeaForm();
	  this.form.initFormFields(conditioninfo);
	}


	@action setSelectedTreeKeys = (key = []) => {
	  this.selectedTreeKeys = key;
	}
}
